<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>02mixin</title>
  <script src="../../js/vue.js"></script>
</head>

<body>
  <div id="app">
  </div>
  <script>
    var mixin = {
      data: function () {
        return {
          message: 'hello',
          foo: 'abc'
        }
      },
      methods: {
        conflicting: function () {
          console.log('from mixin')
        }
      },
      created: function () {
        console.log('混入对象的钩子被调用')
      }
    }
    var vm = new Vue({
      el: '#app',
      mixins: [mixin],
      data: function () {
        return {
          message: 'goodbye',
          bar: 'def'
        }
      },
      methods: {
        conflicting: function () {
          console.log('from self')
        }
      },
      created: function () {
        console.log('组件钩子被调用')
        console.log(this.$data)
        // => { message: "goodbye", foo: "abc", bar: "def" }
      }
    })
    vm.conflicting() // => "from self"
  </script>
</body>

</html>